<<<<<<< HEAD
import gradio as gr
import requests

# 假设这是你的DeepSeek API的URL和API密钥
DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions"
API_KEY = "sk-075ce000cda8491191ba85fd68802c97"


def ask_deepseek(question):
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }

    data = {
        "model": "deepseek-chat",  # 假设这是你要使用的模型
        "messages": [{"role": "user", "content": question}]
    }

    response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data)

    if response.status_code == 200:
        result = response.json()
        # 假设API返回的回答在result['choices'][0]['message']['content']
        answer = result['choices'][0]['message']['content']
        return answer
    else:
        return f"Error: {response.status_code}, {response.text}"


# 创建Gradio界面
iface = gr.Interface(
    fn=ask_deepseek,  # 调用DeepSeek API的函数
    inputs="text",  # 输入是一个文本框
    outputs="text",  # 输出也是一个文本框
    title="DeepSeek Chatbot",
    description="Ask anything to the DeepSeek chatbot!"
)

# 启动Gradio应用
=======
import gradio as gr
import requests

# 假设这是你的DeepSeek API的URL和API密钥
DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions"
API_KEY = "sk-075ce000cda8491191ba85fd68802c97"


def ask_deepseek(question):
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }

    data = {
        "model": "deepseek-chat",  # 假设这是你要使用的模型
        "messages": [{"role": "user", "content": question}]
    }

    response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data)

    if response.status_code == 200:
        result = response.json()
        # 假设API返回的回答在result['choices'][0]['message']['content']
        answer = result['choices'][0]['message']['content']
        return answer
    else:
        return f"Error: {response.status_code}, {response.text}"


# 创建Gradio界面
iface = gr.Interface(
    fn=ask_deepseek,  # 调用DeepSeek API的函数
    inputs="text",  # 输入是一个文本框
    outputs="text",  # 输出也是一个文本框
    title="DeepSeek Chatbot",
    description="Ask anything to the DeepSeek chatbot!"
)

# 启动Gradio应用
>>>>>>> a80d71260cbff6853b271b7d393516d0f45c35c7
iface.launch()